﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cricket.LinqData;
using Cricket.LinqModel;


public partial class SetLimit : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    Client client;
    List<Client> clients;

    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bindClient();
        }
    }

    private void bindClient()
    {
        client = new Client(_dataObject);
        HttpCookie cookie = Request.Cookies["Admin"];
        clients = new List<Client>();
        int AdminId = Convert.ToInt32(cookie["AdminId"]);
        List<GetClientsByAdminIdResult> lstClient = new List<GetClientsByAdminIdResult>();
        lstClient = client.GetClientsByAdminId(AdminId);
        if (lstClient.Count > 0)
        {
            rptClientLimit.DataSource = lstClient;
            rptClientLimit.DataBind();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["Admin"];
        
        for (int i = 0; i < rptClientLimit.Items.Count; i++)
        {
            client = new Client(_dataObject);
            TextBox txtId = (TextBox)rptClientLimit.Items[i].FindControl("txtId");
            TextBox txtName = (TextBox)rptClientLimit.Items[i].FindControl("txtName");
            TextBox txtLimit = (TextBox)rptClientLimit.Items[i].FindControl("txtLimit");

            if (!string.IsNullOrEmpty(txtName.Text))
            {
                client.Id = Convert.ToInt32(txtId.Text);
                client.ActualLimit = Convert.ToDecimal(txtLimit.Text);
                client.UpdateClientLimitByAdmin();
            }
        }
    }
}